import requests

resp_login = requests.post(url='http://ihrm-test.itheima.net/api/sys/login',
                           headers={'Content-Type': 'application/json'},
                           json={'mobile': '13800000002', 'password': '123456'})

# 添加员工
token = 'Bearer ' + resp_login.json().get('data')
json_data = {"username": "熊大",
             "mobile": "13699887400",
             "timeOfEntry": "2021-04-01",
             "formOfEmployment": 1,
             "workNumber": "251",
             "departmentName": "测试部",
             "departmentId": "1063678149528784896",
             "correctionTime": "2021-04-29T16:00:00.000Z"}
resp_emp = requests.post(url='http://ihrm-test.itheima.net/api/sys/user',
                         headers={'Content-Type': 'application/json',
                                  'Authorization': token},
                         json=json_data)
print(resp_emp.json())
emp_id = resp_emp.json().get('data').get('id')
print(emp_id)

# 查询员工
resp_query_emp = requests.get(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                              headers={'Content-Type': 'application/json',
                                       'Authorization': token})
print(resp_query_emp.json())

# 修改员工
resp_modify_emp = requests.put(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                               headers={'Content-Type': 'application/json',
                                        'Authorization': token},
                               json={"username": "熊二"})
print(resp_modify_emp.json())

# 再查询员工
resp_query_emp = requests.get(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                              headers={'Content-Type': 'application/json',
                                       'Authorization': token})
print(resp_query_emp.json())

# 删除员工
resp_del_emp = requests.delete(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                               headers={'Content-Type': 'application/json',
                                        'Authorization': token})
print(resp_del_emp.json())

# 查询员工列表
resp_emp_list = requests.get(url='http://ihrm-test.itheima.net/api/sys/user?page=1&size=10',
                             headers={'Content-Type': 'application/json',
                                      'Authorization': token})
print(resp_emp_list.json())
